package com.starlink.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starlink.model.domain.AdminDO;
import com.starlink.model.request.AdminRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhanghong
 */
@Repository
public interface AdminMapper extends BaseMapper<AdminDO> {
    AdminDO selectDOById(Long id);
    List<AdminDO> selectDOList(AdminDO admin);
    int insertDO(AdminDO admin);
    int batchInsertDO(List<AdminDO> adminDOList);
    int updateDO(AdminDO admin);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from admin",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") AdminRequest param);
    @Select({"<script>",
            "   select * from admin",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<AdminDO> pageQuery(@Param("param") AdminRequest param, @Param("limit") int limit, @Param("offset") long offset);

    @Select({"select * from admin where acnt = #{acnt} and pwd = #{pwd} limit 1"})
    AdminDO findByCondition(@Param("acnt") String acnt, @Param("pwd") String pwd);

    @Select({"select * from admin where id = #{id} "})
    AdminDO findById(@Param("id") long id);
}
